package com.my.emf.notification.observers;


import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;

import com.my.emf.notification.model.IPerson;
import com.my.emf.notification.model.IPersonList;
import com.my.emf.notification.model.ModelFactory;

public class ElementObserver {

   private IPersonList persons;

   public ElementObserver() {
      ModelFactory factory = ModelFactory.eINSTANCE;
      persons = factory.createIPersonList();

      Adapter adapter = new AdapterImpl() {

         public void notifyChanged(Notification notification) {
            System.out.println("Notfication received from the data model. Data model has changed!!!");
         }
      };
      persons.eAdapters().add(adapter);
   }

   public void doStuff() {
      ModelFactory factory = ModelFactory.eINSTANCE;
      IPerson person = (IPerson) factory.createIPerson();
      person.setFirstName("Lars");
      System.out.println("I'm adding a person.");
      persons.getPersons().add(person);
      System.out.println("I'm changing a entry");
      persons.getPersons().get(0).setFirstName("Lars2");
   }
}
